package com.gopay.bis.service.bank.impl.mtpay;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;

import com.gopay.bis.common.util.BankLogUtils;
import com.gopay.bis.manager.bank.mtpay.TBankMtPayManager;
import com.gopay.common.Result;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.MtPayBaseMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.MtPayInteractRemoteService;

/**
 * 测试银行无卡实现
 * 
 * @TBankMtPayServiceImpl.java
 * @author WangHongFei
 */
public class TBankMtPayServiceImpl implements MtPayInteractRemoteService{

    @Resource(name = "tbankMtPayManager")
    private TBankMtPayManager tbankMtPayManager;
	
	@Override
	public Result pay(BaseMessage baseMsg) {
        Result result = new Result(false);
        MtPayBaseMessage message = new MtPayBaseMessage();
        BeanUtils.copyProperties(baseMsg, baseMsg);
        try {
        	message = this.tbankMtPayManager.pay(message);
            String tempStr = (String) (message.getMtbPayHashMap().get("retCd"));
            if (StringUtils.isNotBlank(tempStr) && tempStr.startsWith("S")) {
                result.setSuccess(true);
            }
            result.setDefaultModel(message);
		} catch (GopayException e) {
			BankLogUtils.printServiceImplExceptionLog(e);
    		result.setResultCode(e.getErrCode());
		}
        return result;
	}
	
	@Override
	public Result flush(BaseMessage baseMsg) {
        Result result = new Result(false);
        MtPayBaseMessage message = new MtPayBaseMessage();
        BeanUtils.copyProperties(baseMsg, baseMsg);
        try {
        	message = this.tbankMtPayManager.flush(message);
            String tempStr = (String) (message.getMtbPayHashMap().get("retCd"));
            if (StringUtils.isNotBlank(tempStr) && tempStr.startsWith("S")) {
                result.setSuccess(true);
            }
            result.setDefaultModel(message);
		} catch (GopayException e) {
			BankLogUtils.printServiceImplExceptionLog(e);
    		result.setResultCode(e.getErrCode());
		}
        return result;
	}

	@Override
	public Result bankBack(BaseMessage base) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Result query(BaseMessage base) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Result certification(BaseMessage baseMsg) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Result sendSms(BaseMessage baseMsg) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Result checkSms(BaseMessage baseMsg) {
		// TODO Auto-generated method stub
		return null;
	}

}
